<template>
<view>
	<view class="header">支出报表</view>
	<view class="header1">
		<picker mode="date" :value="sdate" @change="bindDate" data-key="sdate">
			<view class="uni-input weui-input">{{sdate ? sdate : '请选择开始日期'}}</view>
		</picker>
		<picker mode="date" :value="edate" @change="bindDate" data-key="edate">
			<view class="uni-input weui-input">{{edate ? edate : '请选择结束日期'}}</view>
		</picker>
		<view class="header_bottom" @click="search">搜索</view>
	</view>
	<view class="table">
		<table border="0" width="95%" cellspacing="0" cellpadding="0">
			<tr>
				<td>支出项目</td>
				<td>支出金额</td>
				<td>日期</td>
			</tr>
			<tr v-for="(item,index) in list" :key="index">
				<td>{{item.title}}</td>
				<td>{{item.price}}</td>
				<td class="size">{{item.addtime}}</td>
			</tr>
		</table>
	</view>
	
	<button v-if="oaRole == 1 || oaRole == 3" @click="addDaily" class="buttonClass">添加支出</button>
	<addDaily v-if="addDailyShow" @func="close"></addDaily>
</view>
</template>
<script>
import request from '@/util/request.js'
import addDaily from "@/components/system/addDaily.vue"//开卡
export default {
	data() {
		return {
			//oaRole 1:店长2:员工3:商户
			oaRole:0,
			list:[],
			page:1,
			pageShow:true,
			sdate:'',
			edate:'',
			addDailyShow:false
		}
	},
	components:{addDaily},
	onLoad:function(){
		this.oaRole = uni.getStorageSync('oaRole')
		uni.showLoading({
		    title: '加载中'  
		});
		this.getList()
	},
	methods: {
		getList:function(){
			var data = {
				oa_id:uni.getStorageSync('oa_id'),
				page:this.page,
				sdate:this.sdate,
				edate:this.edate
			}
			var that = this;
			request({
				url: 'manage/daily/list',
				method: 'get',
				data:data,
				success: (res) => {
					uni.hideLoading();
					if(res.data.data.last_page <= that.page){
						that.pageShow = false
					}
					if(that.page == 1){
					    that.list = res.data.data.data
					}else{
						var list = that.list
					    that.list = list.concat(res.data.data.data)
					}
				}
			})
		},
		onReachBottom:function(e){
			if(this.pageShow){
				this.page = this.page + 1
				uni.showLoading({
				    title: '加载中'  
				});
				this.getList()
			}
		},
		bindDate:function(e){
			var value = e.detail.value
			var name = e.currentTarget.dataset.key
			this[name] = value
		},
		search:function(){
			if(!this.sdate && !this.edate){
				uni.showToast({
					title: '请选择开始日期和结束日期!!!',
					icon: "none", 
					position:'bottom',
				});
				return;
			}
			uni.showLoading({
			    title: '加载中'  
			});
			this.page = 1;
			this.pageShow = true
			this.getList();
		},
		addDaily:function(){
			this.addDailyShow = true
		},
		close:function(){
			this.addDailyShow = false
			this.getList();
		}
	},
}
</script>
<style>
.header{
    width:100%;
    height:80rpx;
    line-height: 80rpx;
    text-align: center;
    background:#00b300;
    color:#fff;
}
.table{
	width:100%;
	padding:10rpx 20rpx 120rpx 20rpx;
}
td{
	border:1rpx solid #C8C7CC;
	text-align: center;
	height:70rpx;
	line-height:70rpx;
}
.size{
	font-size:12px;
}
.header1{
	width:100%;
	height:80rpx;
	display:flex;
	flex-direction: row;
	justify-content: center;
	align-items: center;
}
.header1 picker{
	width:40%;
	text-align: center;
	border:1px dashed #E5E5E5;
}
.header_bottom{
	width:18%;
	height:70rpx;
	line-height: 70rpx;
	background: #009900;
	text-align: center;
	color:#FFFFFF;
}
</style>